package com.zh.web.base;

import com.zh.common.utils.IpUtils;
import com.zh.common.dto.IpDto;
import io.swagger.annotations.Api;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@Api(tags = "基础控制器")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
/**
 * 基础控制器
 */
public class  BaseController extends AbstractBaseController{

    protected Long operator;
    /**
     * 提供一个获取Ip地址的方法
     */
    public IpDto getIpAddress(HttpServletRequest request) {
        IpDto ipDto = new IpDto();
        try {
            String ip = IpUtils.getIp(request);
            String region = IpUtils.getIp2region(ip);
            String cityInfo = IpUtils.getCityInfo(ip);
            ipDto.setIp(ip);
            ipDto.setRegion(region);
            ipDto.setCityInfo(cityInfo);

        } catch (Exception ex){
            log.error("获取ip地址失败:{0}",ex);
        }
        return ipDto;
    }
}
